<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <title>js typing</title>
</head>
<body>
<div id='divTyping'></div>
<script>
    let str = 'js 实现的 打字效果，感觉蛮有趣的。';
    let i = 0;
    let typing = function (){
        let divTyping = document.getElementById('divTyping');
        if (i <= str.length) {
            divTyping.innerHTML = str.slice(0, i++);
            setTimeout('typing()', 50);//递归调用
        }
        else{
            divTyping.innerHTML = str;//结束打字,移除 _ 光标
        }
    };
    typing();
</script>
</body>
</html>
